package com.hjjt.cameralib.opengl;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.Region;
import android.os.Build;
import android.util.AttributeSet;

/**
 * @ProjectName: IntelligentTerminal
 * @Package: com.hjjt.cameralib.opengl
 * @ClassName: RoundGLSurfaceView
 * @Description:
 * @Author: 孙浩
 * @CreateDate: 2022/8/17 9:16
 */
public class RoundGLSurfaceView  extends  GLFrameSurface{

    private Path clipPath;

    public RoundGLSurfaceView(Context context) {
        super(context);
        init();
    }

    public RoundGLSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {

    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        Path path = new Path();
        // 坐标转换为实际像素
        int w = getWidth();
        int h = getHeight();
        int radius = Math.min(w >> 1, h >> 1);
        path.addCircle(w >> 1, h >> 1, radius, Path.Direction.CW);
        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));
        if (Build.VERSION.SDK_INT >= 26) {
            canvas.clipPath(path);
        } else {
            canvas.clipPath(path, Region.Op.REPLACE);
        }
        super.dispatchDraw(canvas);
    }




}
